package com.zm.admin.saToken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.zm.admin.zmeng.domain.ZmMenu;
import com.zm.admin.zmeng.mapper.ZmMenuMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/***
 *
 * @Auther: MuYun
 * @Date: 2022/4/8 16:39
 * @Description： SaToken自定义权限验证接口
 *
 */
@Component
public class SaTokenAuth implements StpInterface {

    private Logger logger= LoggerFactory.getLogger(this.getClass());

    @Resource
    private ZmMenuMapper zmMenuMapper;

    //没记错是时刻刷新
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<String> permissionList=new ArrayList<>();
        try{
            String id=(String)StpUtil.getLoginId();
            //logger.info("获取到登陆id：{}",StpUtil.getLoginId().toString());
            List<ZmMenu> zmMenus = zmMenuMapper.selectMenuByUserId(StpUtil.getLoginId().toString());
            permissionList=zmMenus.stream().map(ZmMenu::getPermission).collect(Collectors.toList());
            //logger.info("权限码集合：{}",permissionList);
        }catch (Exception e){
            logger.error("{}");
        }
        return permissionList;
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return null;
    }
}
